using System;
using System.Collections.Generic;
using System.Text;

namespace MindFactorial.LaunchPoint.Common
{
    /// <summary>
    /// Represents a generic dictionary
    /// </summary>
    /// <typeparam name="K"></typeparam>
    /// <typeparam name="V"></typeparam>
    public abstract class GenericDictionary<K,V> : ImmortalIPCObject, IModifyableCollection<K,V> 
    {
        /// <summary>
        /// the encapsulated dictionary
        /// </summary>
        protected Dictionary<K, V> _items = new Dictionary<K, V>();

        /// <summary>
        /// indexes the list of items in the dictionary
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public virtual V this[K key]
        {
            get
            {
                return _items[key];
            }
        }

        /// <summary>
        /// gets an enumerator used to iterate through the list of items
        /// </summary>
        /// <returns></returns>
        public System.Collections.IEnumerator GetEnumerator()
        {
            return _items.GetEnumerator();
        }

        /// <summary>
        /// adds a new item
        /// </summary>
        /// <param name="key"></param>
        /// <param name="item"></param>
        public void Add(K key, V item)
        {
            if (!_items.ContainsKey(key))
                _items.Add(key, item);
            else
                _items[key] = item;
        }

        /// <summary>
        /// removes an item
        /// </summary>
        /// <param name="key"></param>
        public void Remove(K key)
        {
            _items.Remove(key);
        }

       
    }
}
